#include "main.h"
void SystemClock_Config(void)
{

  RCC_OscInitTypeDef RCC_OscInitStruct = {0};
  RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};

  /** Initializes the CPU, AHB and APB busses clocks 
  */
  RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI;
  RCC_OscInitStruct.HSIState = RCC_HSI_ON;
  RCC_OscInitStruct.HSICalibrationValue = RCC_HSICALIBRATION_DEFAULT;
  RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
  RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSI;
  RCC_OscInitStruct.PLL.PLLMUL = RCC_PLL_MUL6;��Ƶ��48mhz
  RCC_OscInitStruct.PLL.PREDIV = RCC_PREDIV_DIV1;
  if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
  {
    Error_Handler();
  }
  /** Initializes the CPU, AHB and APB busses clocks 
  */
  RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK
                              |RCC_CLOCKTYPE_PCLK1;
  RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
  RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
  RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV1;

  if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_1) != HAL_OK)
  {
    Error_Handler();
  }
}


u32 atou(s8 *str)
{
	const s8 * s = str;
	u64 result = 0;
	
	if (str == NULL) {
		return result;
	}

	while (*s == ' ') {
		s++;
	}

	while (*s >= '0' && *s <= '9' ) {
		result = result * 10 + (*s - '0');
		if ((result & 0xffffffff00000000)) {
			result = result / 10;
			break;
		}
		s++;
	}

	return (u32)result;
}


s32 RtspGetStringContent(s8 *buf, s8 *title, s8 *content)
{
    s8 *start = NULL;
    s8 *end = NULL;
    s32 len = 0;
    if (buf == NULL || title == NULL || content == NULL) {
        printf("check args null");
        return -1;
    }

    start = strstr(buf, title);
    if (start == NULL) {
        
        return -1;
    }

    start += strlen(title);
    while (*start == ' ') {
        start++;
    }

    end = strstr(start, "\r\n");
    if (end == NULL) {
        printf("can't find line end");
        return -1;
    }

    len = end - start;
    strncpy(content, start, len);
    content[len] ='\0';
    return len;
}

u32 UtilGetIntFlag(u8 *buf,u8*flag)
{
    s8  tmpBuf[128];
    s32 ret;
    memset(tmpBuf, 0, sizeof(tmpBuf));
    ret = RtspGetStringContent(buf, flag, tmpBuf);
    if (ret > 0) {
        return (u32)atou(tmpBuf);
    }
    return 0;
}

uint8 UtilFindStringContent(const uint8* str,uint8 slen, const uint8* des)
{
    uint8	i=0,j=0;
	for(i=0;i<slen;i++)
	{
		if(str[i]==des[0]&&((i+strlen(des)-1)<=slen))
		{
			printf("i=%d\n",i);
			for(j=0;j<strlen(des);j++)
			{
				if(str[i+j]!=des[j])
				{
					printf("j=%d\n",j);
					break;
				}
	
			}
			if(j==strlen(des))
			{
				
				return TRUE;
			}
		
		}


	}
	printf("bbbbbb");
    return FALSE;
}

